﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 

namespace MaxStudio.Concrete.Server.Service
{
    public class LinkmanService : ServiceHandle, ILinkman
    {
        #region ILinkman Members
     //   ConcreteDaoDataContext dataContext = new ConcreteDaoDataContext();
        public OperationResult<List<tb_Linkman>> GetAllLinkman()
        {
            ConcreteDaoDataContext dataContext = getDateContext();

            OperationResult<List<tb_Linkman>> result = new OperationResult<List<tb_Linkman>>();
            List<tb_Linkman> list = new List<tb_Linkman>();
            try
            {
                list = dataContext.GetAllLinkman();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_Linkman> GetLinkmanById(int id)
        {
            OperationResult<tb_Linkman> result = new OperationResult<tb_Linkman>();
            ConcreteDaoDataContext dataContext = getDateContext();

            tb_Linkman linkman;
            try
            {
                linkman = dataContext.GetLinkmanById(id);
                if (linkman == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = linkman;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_Linkman> CreateLinkman(tb_Linkman entity)
        {
            OperationResult<tb_Linkman> result = new OperationResult<tb_Linkman>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.CreateLinkman(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_Linkman> ModifyLinkman(tb_Linkman entity)
        {
            OperationResult<tb_Linkman> result = new OperationResult<tb_Linkman>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.ModifyLinkman(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_Linkman> DeleteLinkman(tb_Linkman entity)
        {
            OperationResult<tb_Linkman> result = new OperationResult<tb_Linkman>();
            ConcreteDaoDataContext dataContext = getDateContext();

            try
            {
                dataContext.DeleteLinkman(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
